"""Sumarize RNA Degradation

.. helpdoc::

"""

"""<widgetXML>
    <name>Sumarize RNA Degradation</name>
    <icon>Default.png</icon>
    <tags> 
        <tag>Microarray</tag> 
    </tags>
    <summary>Summary of RNA Degradation from affy data.  Takes an RNA Degradation Signal</summary>
    <author>
        <authorname>Kyle R Covington</authorname>
        <authorcontact>kyle@red-r.org</authorcontact>
    </author>
</widgetXML>
"""


"""
<name>Sumarize RNA Degradation</name>
<author>Generated using Widget Maker written by Kyle R. Covington</author>
<RFunctions>affy:summaryAffyRNAdeg</RFunctions>
<tags>Affy QC</tags>
<icon></icon>
"""
from OWRpy import * 
import redRGUI 
import libraries.affy.signalClasses as signals
import libraries.affy.signalClasses.RAffyBatch as rab
class RedRsummaryAffyRNAdeg(OWRpy): 
    settingsList = []
    def __init__(self, **kwargs):
        OWRpy.__init__(self, **kwargs)
        self.require_librarys(["affy"])
        self.RFunctionParam_abatch = ''
        self.RFunctionParam_rna_deg_obj = ''
        self.inputs.addInput('rnaDeg', "RNA Degradation Object", signals.DegFit.DegFit, self.processrna_deg_obj)
        #self.inputs.addInput('affyBatch', 'Affybatch Object', signals.RAffyBatch.RAffyBatch, self.processabatch)
        
        self.RFunctionParamsignif_digits_spinBox =  redRSpinBox(self.controlArea,  label = "Significant Digits:", min = 0, max = 5, value = 3)
        self.ROutputWindow = redRTextEdit(self.controlArea, label = 'Summary')
        redRCommitButton(self.bottomAreaRight, "Commit", callback = self.commitFunction)
    #def processabatch(self, data):
        #if data:
            #self.RFunctionParam_abatch=data.getData()
            ##self.data = data
            #self.commitFunction()
        #else:
            #self.RFunctionParam_abatch=''
    def processrna_deg_obj(self, data):
        if data:
            self.RFunctionParam_rna_deg_obj=data.getData()
            #self.data = data
            self.commitFunction()
        else:
            self.RFunctionParam_rna_deg_obj=''
    def commitFunction(self):
        if unicode(self.RFunctionParam_rna_deg_obj) == '': return
        #if unicode(self.RFunctionParam_abatch) == '': return
        injection = []
        
        string = 'signif.digits='+unicode(self.RFunctionParamsignif_digits_spinBox.value())+''
        injection.append(string)
        inj = ','.join(injection)
        self.R('txt<-capture.output('+'summaryAffyRNAdeg(rna.deg.obj='+str(self.RFunctionParam_rna_deg_obj)+','+inj+'))', wantType = 'NoConversion') # abatch='+str(self.RFunctionParam_abatch)+',
        self.ROutputWindow.clear()
        tmp = self.R('paste(txt, collapse ="\n")')
        self.ROutputWindow.insertPlainText(tmp)